package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.WorkAnnexBean;
import com.zyf.fwms.commonlibrary.utils.AutoUtils;

import java.util.List;

/**
 * 工单信息  附件 --adapter
 *
 * Created by Administrator on 2017/9/6.
 */

public class WorkAnnexAdapter extends RecyclerView.Adapter<WorkAnnexAdapter.WorkAnnexViewHolder>{

    private LayoutInflater inflater;
    private Context context;
    private List<WorkAnnexBean.Rows> mList;

    private OnItemClickListener mOnItemClickListener;

    public WorkAnnexAdapter(Context context,List<WorkAnnexBean.Rows> mList){
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.mList = mList;
    }

    @Override
    public WorkAnnexViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view =  inflater.inflate(R.layout.item_work_annex,null);
        AutoUtils.auto(view);
        return new WorkAnnexAdapter.WorkAnnexViewHolder(view);
    }

    @Override
    public void onBindViewHolder(WorkAnnexViewHolder holder, int position) {
        WorkAnnexBean.Rows rows = mList.get(position);

        holder.tvName.setText(rows.getAttachName());
        holder.tvCreate.setText("创建工单");
        holder.tvSize.setText("/"+rows.getAttachSize());
//        holder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//            }
//        });
    }

    @Override
    public int getItemCount() {
        return mList == null?0:mList.size();
    }


    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener{
        void onItemClick(View view, int position);
    }

    static class WorkAnnexViewHolder extends RecyclerView.ViewHolder{
        private View itemView;
        private TextView tvName;//图片名称
        private TextView tvCreate;//创建
        private TextView tvSize;//图片大小

        public WorkAnnexViewHolder(View view) {
            super(view);
            itemView = view;
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvCreate = (TextView) itemView.findViewById(R.id.tv_create);
            tvSize = (TextView) itemView.findViewById(R.id.tv_size);
        }
    }

}
